/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mapping;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Andres
 */
@Entity
@Table(name = "cambio_comp")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CambioComp.findAll", query = "SELECT c FROM CambioComp c"),
    @NamedQuery(name = "CambioComp.findByIdTicket", query = "SELECT c FROM CambioComp c WHERE c.cambioCompPK.idTicket = :idTicket"),
    @NamedQuery(name = "CambioComp.findByIdComponente", query = "SELECT c FROM CambioComp c WHERE c.cambioCompPK.idComponente = :idComponente")})
public class CambioComp implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CambioCompPK cambioCompPK;
    @JoinColumn(name = "idComponenteCambio", referencedColumnName = "id")
    @ManyToOne
    private Componentes idComponenteCambio;
    @JoinColumn(name = "idComponente", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Componentes componentes;
    @JoinColumn(name = "idTicket", referencedColumnName = "idTicket", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Ticket ticket;

    public CambioComp() {
    }

    public CambioComp(CambioCompPK cambioCompPK) {
        this.cambioCompPK = cambioCompPK;
    }

    public CambioComp(String idTicket, int idComponente) {
        this.cambioCompPK = new CambioCompPK(idTicket, idComponente);
    }

    public CambioCompPK getCambioCompPK() {
        return cambioCompPK;
    }

    public void setCambioCompPK(CambioCompPK cambioCompPK) {
        this.cambioCompPK = cambioCompPK;
    }

    public Componentes getIdComponenteCambio() {
        return idComponenteCambio;
    }

    public void setIdComponenteCambio(Componentes idComponenteCambio) {
        this.idComponenteCambio = idComponenteCambio;
    }

    public Componentes getComponentes() {
        return componentes;
    }

    public void setComponentes(Componentes componentes) {
        this.componentes = componentes;
    }

    public Ticket getTicket() {
        return ticket;
    }

    public void setTicket(Ticket ticket) {
        this.ticket = ticket;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cambioCompPK != null ? cambioCompPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CambioComp)) {
            return false;
        }
        CambioComp other = (CambioComp) object;
        if ((this.cambioCompPK == null && other.cambioCompPK != null) || (this.cambioCompPK != null && !this.cambioCompPK.equals(other.cambioCompPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mapping.CambioComp[ cambioCompPK=" + cambioCompPK + " ]";
    }
    
}
